package com.zmn.oms.model.vo.call;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.string.StringUtil;
import lombok.*;

import java.io.Serializable;
import java.util.Date;

/**
 * <p> 类描述: 通话记录
 *
 * @author Yangk
 * @version 1.0
 * @date 2019年3月30日
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CallRecords implements Serializable {

    private Integer id;

    private String bizId;

    private Integer callType;

    private Integer bizType;

    private String bizTypeName;

    private Integer agentsId;

    private Integer clusterId;

    private String clusterName;

    private Integer groupId;

    private String groupName;

    private Integer staffId;

    private String staffName;

    private Integer ccDeptId;

    private String ccDeptName;

    private String realName;

    private String from;

    /**
     * 用户类型
     * 1 新用户  2 老用户  3 工程师
     * 2019年11月1日
     */
    private Integer userType;

    private String to;

    private String trunkNo;

    private Integer trunkType;

    private Integer channelId;

    private String channelName;

    private Integer localChannelId;

    private String localChannelName;

    private String phone400;

    private Integer mnoId;

    private String mnoName;

    private Integer cityId;

    private String cityName;

    private Integer byeWay;

    private Integer byeUser;

    private Integer callBackStatus;

    private Date moStartTime;

    private Date moEndTime;

    private Long moDuration;

    private Long ringDuration;

    private Long waitRingDuration;

    private Long waitDuration;

    private Date mtStartTime;

    private Date mtEndTime;

    private Long mtDuration;

    private Integer callStatus;

    private String tapeUrl;

    private String keys;

    private Integer transferWay;

    private String forwardFrom;

    private String forwardTo;

    private String userEvaluation;

    private String creater;

    private String updater;

    private Date createTimeDay;

    private Date createTime;

    private Date updateTime;

    private Integer thirdId;

    private Long orderId;

    private String recordsDelegateKey;

    private Integer extId;

    private String extension;

    /**
     * 等待响铃 开始时间 (即分配成功后)
     */
    private Date waitRingStartTime;

    /**
     * 响铃开始时间(即等待响铃结束后)
     */
    private Date ringStartTime;

    /**
     * 等待队列开始时间
     */
    private Date waitQueueStartTime;

    public String getMoDurationFormat() {
        if (moDuration == null || moDuration == 0L) {
            return "0''";
        }
        return DateUtil.getDurationDesc(this.moDuration);
    }

    public String getRingDurationFormat() {
        if (ringDuration == null || ringDuration == 0L) {
            return "0''";
        }
        return DateUtil.getDurationDesc(this.ringDuration);
    }

    public String getWaitRingDurationFormat() {
        if (waitRingDuration == null || waitRingDuration == 0L) {
            return "0''";
        }
        return DateUtil.getDurationDesc(this.waitRingDuration);
    }

    public String getWaitDurationFormat() {
        if (waitDuration == null || waitDuration == 0L) {
            return "0''";
        }
        Long compareValue = 1000L;
        if (waitDuration > compareValue) {
            Long millsValue = waitDuration % 1000L;
            return DateUtil.getDurationMillsDesc(this.waitDuration) + millsValue;
        } else {
            return "0''" + waitDuration;
        }
    }

    public String getMtDurationFormat() {
        if (mtDuration == null || mtDuration == 0L) {
            return "0''";
        }
        return DateUtil.getDurationDesc(this.mtDuration);

    }

    public String getMtOutDurationFormat() {
        Long longTen = 10L;
        if (mtDuration == null || mtDuration - longTen <= 0L) {
            return "0''";
        }
        return DateUtil.getDurationDesc(this.mtDuration - longTen);
    }

    public String getByeUserString() {
        if (byeUser == null) {
            return "--";
        }
        switch (byeUser.intValue()) {
            case 0:
                return "用户挂断";
            case 1:
                return "用户挂断";
            case 2:
                return "坐席挂断";
            case 3:
                return "系统挂断";
            default:
                return "异常挂断";
        }
    }

    public String getFromCover() {
        if (StringUtil.isBlank(this.from)) {
            return "";
        }
        int length = this.from.length();
        int countFour = 4;
        int countEight = 8;
        if (length <= countFour) {
            String result = "";
            for (int i = 0; i < length; i++) {
                result += "*";
            }
            return this.from;
        } else if (length <= countEight) {
            return this.from.substring(0, 2) + "****" + this.from.substring(length - 2, length);
        } else {
            return this.from.substring(0, 3) + "****" + this.from.substring(length - 4, length);
        }
    }

    public String getToCover() {
        if (StringUtil.isBlank(this.to)) {
            return "";
        }
        int length = this.to.length();
        int countFour = 4;
        int countEight = 8;
        if (length <= countFour) {
            String result = "";
            for (int i = 0; i < length; i++) {
                result += "*";
            }
            return this.to;
        } else if (length <= countEight) {
            return this.to.substring(0, 2) + "****" + this.to.substring(length - 2, length);
        } else {
            return this.to.substring(0, 3) + "****" + this.to.substring(length - 4, length);
        }
    }

    public String getTrunkTypeString() {
        String trunkTypeString;
        if (this.trunkType == null) {
            return "未知类型";
        }
        switch (this.trunkType.intValue()) {
            case 1:
                trunkTypeString = "子公司线路";
                break;
            case 2:
                trunkTypeString = "10101016";
                break;
            case 3:
                trunkTypeString = "言而有信座机";
                break;
            default:
                trunkTypeString = "未知类型";
        }
        return trunkTypeString;
    }

    /**
     * 1领单催单;2联系催单;3时效催单;4打开APP;5正常业务;6信息中心;
     *
     * @return
     */
    public String getBusinessTypeString() {
        String bussinessTypeString;
        if (this.bizType == null) {
            return "未知类型";
        }
        switch (this.bizType.intValue()) {
            case 1:
                bussinessTypeString = "订单催单";
                break;
            case 2:
                bussinessTypeString = "打开APP";
                break;
            case 3:
                bussinessTypeString = "投诉异常";
                break;
            case 5:
                bussinessTypeString = "正常业务";
                break;
            case 6:
                bussinessTypeString = "信息中心";
                break;
            default:
                bussinessTypeString = "未知类型";
                break;
        }
        return bussinessTypeString;
    }
}
